package cn.wolfcode.wolf2w.business.listener;

import cn.wolfcode.wolf2w.business.api.domain.NoteCanal;
import com.alibaba.fastjson.JSON;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import top.javatool.canal.client.annotation.CanalTable;
import top.javatool.canal.client.handler.EntryHandler;

@Component
@CanalTable("ta_note")
public class NoteListener implements EntryHandler<NoteCanal> {
    @Autowired
    private AmqpTemplate amqpTemplate;

    @Override
    public void insert(NoteCanal noteCanal) {
        System.out.println(noteCanal);
        String jsonString = JSON.toJSONString(noteCanal);
        //发送rabbitmq消息，添加canal后在canal中发送
        amqpTemplate.convertAndSend("noteExchange","note.insert",jsonString);
    }


}
